<?php
namespace Admin\Controller;
use Think\Controller;
class WorksController extends CommonController {
    public function index(){
      $this->works=M('works')->select();
      $this->display();
    }

    public function edit($id=""){
      $this->work=M('works')->find($id);
      $this->display();
    }

    public function delWork(){
      if(M('works')->delete(I("get.id")))
        $this->success("删除成功");
      else $this->error("删除失败");
    }

    public function addWorks(){
      $config = array(
          'maxSize'    =>    3145728,
          'rootPath'   =>    './Public/img/',
          'savePath'   =>    '',
          'saveName'   =>    array('date','Ymdhis'),
          'exts'       =>    array('jpg', 'gif', 'png', 'jpeg'),
          'autoSub'    =>    false,
      );
      $upload = new \Think\Upload($config);// 实例化上传类\
       // 上传文件
       $info   =   $upload->upload();
       if(!$info) {// 上传错误提示错误信息
           $this->error($upload->getError());die();
       }
       $data=I('post.');
       $data['preview']=$info['preview']['savename'];
       if(M('works')->add($data))
        $this->success("添加成功");
       else $this->error("添加失败");
    }
}
